/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

/**
 * Unit answer header id (composite PK). PK of a persistent class.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class SurveyUnitAnswerId implements java.io.Serializable {
	/**
	 * The survey answer header.
	 */
	private SurveyAnswerHeader header;

	/**
	 * The question.
	 */
	private Question question;

/**
   * Constructor.
   */
	public SurveyUnitAnswerId() {
	}

	/**
	 * Retrieves the header.
	 *
	 * @return the header.
	 */
	public SurveyAnswerHeader getHeader() {
		return this.header;
	}

	/**
	 * Sets the header.
	 *
	 * @param header the header.
	 */
	public void setHeader(SurveyAnswerHeader header) {
		this.header = header;
	}

	/**
	 * Retrieves the question.
	 *
	 * @return the question.
	 */
	public Question getQuestion() {
		return this.question;
	}

	/**
	 * Sets the question.
	 *
	 * @param question the question.
	 */
	public void setQuestion(Question question) {
		this.question = question;
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if((o == null) || (getClass() != o.getClass())) {
			return false;
		}

		SurveyUnitAnswerId that = (SurveyUnitAnswerId)o;

		if((getHeader() != null) ? (!getHeader().equals(that.getHeader())) : (that.getHeader() != null)) {
			return false;
		}

		if((getQuestion() != null) ? (!getQuestion().equals(that.getQuestion())) : (that.getQuestion() != null)) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		int result = (getHeader() != null) ? getHeader().hashCode() : 0;

		result = (31 * result) + ((getQuestion() != null) ? getQuestion().hashCode() : 0);

		return result;
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("SurveyUnitAnswerId");
		sb.append("{header=").append(getHeader());
		sb.append(", question=").append(getQuestion());
		sb.append('}');

		return sb.toString();
	}
}
